package com.example.waterorder.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.waterorder.entity.Worker;
import com.example.waterorder.mapper.UserMapper;
import com.example.waterorder.mapper.WorkerMapper;
import com.example.waterorder.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class WorkerServiceImpl extends ServiceImpl<WorkerMapper, Worker> implements WorkerService {
    @Resource
    private WorkerMapper workerMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public Worker selectById(String userId) {
        return workerMapper.selectById(userId);
    }

    @Override
    public Integer register(Worker worker) {
        int insert = workerMapper.insert(worker);
        if (insert==1)
        {
            userMapper.deleteById(worker.getOpenId());
        }
        return insert;
    }

    @Override
    public Integer updateWorker(Worker worker) {
        return workerMapper.updateById(worker);
    }
}
